<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生命周期</title>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Image extends React.Component{
            render(){
                console.log('4-更新中....')
                return <img src={this.props.src} alt="" />;
            }

            //component 组件  will 将要  receive 接收  props 属性
            componentWillReceiveProps(){
                console.log('1-组件将要接收父级传入的属性数据')
            }

            shouldComponentUpdate(){
                console.log('2-组件应该要更新了');
                return true;
            }

            componentWillUpdate(){
                console.log('3-组件将要更新')
            }

            componentDidUpdate(){
                console.log('5-组件完成更新');
            }

        }

        class App extends React.Component{
            state = {
                keyword: 'game'
            }

            render(){
                return <div>
                        <button onClick={this.change('car')}>汽车</button>
                        <button onClick={this.change('city')}>城市</button>
                        <button onClick={this.change('animal')}>动物</button>
                        <hr />
                        <Image src={"https://source.unsplash.com/500x400?" + this.state.keyword} /> 
                    </div>
            }

            //声明方法
            change = (type) => {
                return () => {
                    this.setState({
                        keyword: type
                    })
                }
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));


    </script>
</body>
</html>